import type { DoctorPage, FollowType, KnowledgePage, KnowledgeParams, PageParams, TopDep, Image, ConsultOrderPreData,
ConsultOrderPreParams, 
PartialConsult,
ConsultOrderItem,
ConsultOrderPage} from "@/types/consult"
import { request } from "@/utils/request"

// 获取百科文章列表
export const getKnowledgePage = (params: KnowledgeParams) =>
    request<KnowledgePage>('patient/home/knowledge', 'GET', params)

// 获取关注医生的列表
export const getDoctorPage = (params: PageParams) =>
    request<DoctorPage>('home/page/doc', 'GET', params)

// 关注医生
export const followDoctor = (id: string, type: FollowType = 'doc') =>
    request('/like', 'POST', { id, type })

// 获取科室列表
export const getAllDep = () => request<TopDep[]>('/dep/all')

// 上传图片
export const uploadImage = (file: File) => {
    const fd = new FormData()
    fd.append('file', file)
    return request<Image>('upload', 'POST', fd)
}

// 拉取预支付订单信息
export const getConsultOrderPre = (params: ConsultOrderPreParams) =>
    request<ConsultOrderPreData>('patient/consult/order/pre', 'GET', params)

// 生成问诊订单
export const createConsultOrder = (data: PartialConsult) => 
    request<{ id: string }>('patient/consult/order', 'POST', data)

// 获取支付地址 0是微信 1是支付宝
export const getConsultOrderPayurl = (params: {
    paymentMethod: 0 | 1
    orderId: string
    payCallback: string
}) => request<{ payUrl: string}>('patient/consult/pay', 'POST', params)

// 订单详情
export const getConsultOrderDetail = (orderId: string) =>
    request<ConsultOrderItem>('patient/consult/order/detail', 'GET', { orderId })

/**
 * 查看处方
 * @param id 
 * @returns 
 */
export const getPrescriptionPic = (id: string) => 
    request<{ url: string }>(`patient/consult/prescription/${id}`)

/**
 * 提交评价
 * @param data 
 * @returns 
 */
export const evaluateConsultOrder = (data: {
    docId: string
    orderId: string
    score: number
    content: string
    anonymousFlag: 0 | 1
}) => request<{ id: string }>('patient/order/evaluate', 'POST', data)

/**
 * 问诊记录分页查询
 * @param params 
 * @returns 
 */
export const getConsultOrderList = (params: ConsultOrderPreParams) => 
    request<ConsultOrderPage>('patient/consult/order/list', 'GET', params)

/**
 * 取消订单
 * @param id 
 * @returns 
 */
export const cancelOrder = (id: string) => request(`patient/order/cancel/${id}`, 'PUT')

/**
 * 删除订单
 * @param id 
 * @returns 
 */
export const deleteOrder = (id: string) => request(`/patient/order/${id}`, 'DELETE')